78b220a325437ee98c0c446273e5c9d072fe1e34,bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatTest.java,HeartbeatTest,doTestSlowAndFastMachine,#boolean#,414
Before Change
// now let the slow machine be slow while the fast one updates as expected
logger.info("doTestSlowAndFastMachine: last heartbeat of slowMachine.");
hhSlow.issueHeartbeat();
logger.info("doTestSlowAndFastMachine: while the fastMachine still sends heartbeats...");
for(int i=0; i<6; i++) {
Thread.sleep(1500);
hhFast.issueHeartbeat();
hhFast.doCheckView();
}
logger.info("doTestSlowAndFastMachine: now the fastMachine should have decoupled the slow one");
fastMachine.dumpRepo();
hhFast.doCheckView(); // one more for the start of the vote
fastMachine.dumpRepo();
hhFast.doCheckView(); // and one for the promotion
// after 9 sec hhSlow's heartbeat will have timed out, so hhFast will not see hhSlow anymore
fastMachine.dumpRepo();
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGED, fastListener.getLastEvent().getType());
assertEquals(3, fastListener.getEventCount());
assertEquals(1, fastMachine.getDiscoveryService().getTopology().getInstances().size());
TopologyView topo = slowMachine.getDiscoveryService().getTopology();
assertFalse(topo.isCurrent());
// after those 6 sec, hhSlow does the check (6sec between heartbeat and check)
logger.info("doTestSlowAndFastMachine: slowMachine is going to do a checkView next - and will detect being decoupled");
hhSlow.doCheckView();
slowMachine.dumpRepo();
logger.info("doTestSlowAndFastMachine: slowMachine is going to also do a heartbeat next");
hhSlow.issueHeartbeat();
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGED, fastListener.getLastEvent().getType());
assertEquals(3, fastListener.getEventCount());
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGING, slowListener.getLastEvent().getType());
assertEquals(2, slowListener.getEventCount());
Thread.sleep(8000);
// even after 8 sec the slow lsitener did not send a TOPOLOGY_CHANGED yet
logger.info("doTestSlowAndFastMachine: after another 8 sec of silence from slowMachine, it should still remain in CHANGING state");
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGING, slowListener.getLastEvent().getType());
assertFalse(slowMachine.getDiscoveryService().getTopology().isCurrent());
assertEquals(2, slowListener.getEventCount());
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGED, fastListener.getLastEvent().getType());
assertEquals(1, fastMachine.getDiscoveryService().getTopology().getInstances().size());
assertEquals(3, fastListener.getEventCount());
// make few rounds of heartbeats so that the two instances see each other again
logger.info("doTestSlowAndFastMachine: now let both fast and slow issue heartbeats...");
for(int i=0; i<4; i++) {
hhFast.issueHeartbeat();
hhFast.doCheckView();
hhSlow.issueHeartbeat();
hhSlow.doCheckView();
Thread.sleep(1000);
}
logger.info("doTestSlowAndFastMachine: by now the two should have joined");
After Change
// now let the slow machine be slow while the fast one updates as expected
logger.info("doTestSlowAndFastMachine: last heartbeat of slowMachine.");
synchronized(lock(hhSlow)) {
hhSlow.issueHeartbeat();
}
logger.info("doTestSlowAndFastMachine: while the fastMachine still sends heartbeats...");
for(int i=0; i<6; i++) {
Thread.sleep(1500);
synchronized(lock(hhFast)) {
hhFast.issueHeartbeat();
hhFast.doCheckView();
}
}
logger.info("doTestSlowAndFastMachine: now the fastMachine should have decoupled the slow one");
fastMachine.dumpRepo();
hhFast.doCheckView(); // one more for the start of the vote
fastMachine.dumpRepo();
hhFast.doCheckView(); // and one for the promotion
// after 9 sec hhSlow's heartbeat will have timed out, so hhFast will not see hhSlow anymore
fastMachine.dumpRepo();
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGED, fastListener.getLastEvent().getType());
assertEquals(3, fastListener.getEventCount());
assertEquals(1, fastMachine.getDiscoveryService().getTopology().getInstances().size());
TopologyView topo = slowMachine.getDiscoveryService().getTopology();
assertFalse(topo.isCurrent());
// after those 6 sec, hhSlow does the check (6sec between heartbeat and check)
logger.info("doTestSlowAndFastMachine: slowMachine is going to do a checkView next - and will detect being decoupled");
hhSlow.doCheckView();
slowMachine.dumpRepo();
logger.info("doTestSlowAndFastMachine: slowMachine is going to also do a heartbeat next");
synchronized(lock(hhSlow)) {
hhSlow.issueHeartbeat();
}
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGED, fastListener.getLastEvent().getType());
assertEquals(3, fastListener.getEventCount());
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGING, slowListener.getLastEvent().getType());
assertEquals(2, slowListener.getEventCount());
Thread.sleep(8000);
// even after 8 sec the slow lsitener did not send a TOPOLOGY_CHANGED yet
logger.info("doTestSlowAndFastMachine: after another 8 sec of silence from slowMachine, it should still remain in CHANGING state");
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGING, slowListener.getLastEvent().getType());
assertFalse(slowMachine.getDiscoveryService().getTopology().isCurrent());
assertEquals(2, slowListener.getEventCount());
assertEquals(TopologyEvent.Type.TOPOLOGY_CHANGED, fastListener.getLastEvent().getType());
assertEquals(1, fastMachine.getDiscoveryService().getTopology().getInstances().size());
assertEquals(3, fastListener.getEventCount());
// make few rounds of heartbeats so that the two instances see each other again
logger.info("doTestSlowAndFastMachine: now let both fast and slow issue heartbeats...");
for(int i=0; i<4; i++) {
synchronized(lock(hhFast)) {
hhFast.issueHeartbeat();
hhFast.doCheckView();
}
synchronized(lock(hhSlow)) {
hhSlow.issueHeartbeat();
hhSlow.doCheckView();
}
Thread.sleep(1000);
}